package com.societyGames.interceptExercises
{
public class AddExpression implements INumberExpression
{
  private var _left:INumberExpression;
  private var _right:INumberExpression;

  public function AddExpression(xml:XML)
  {
    if (!("left" in xml) || !("right" in xml))
    {
      throw new ArgumentError("AddExpression requires left and right children.");
    }
    this._left = Parser.parse(xml.left.children()[0]);
    this._right = Parser.parse(xml.right.children()[0]);
  }

  public function toString():String
  {
    return "add(" + Object(this._left).toString() + ", " + Object(this._right).toString() + ")";
  }

  //INumberExpression-->
  public function evaluate():Number
  {
    return this._left.evaluate() + this._right.evaluate();
  }

  //<--INumberExpression
}
}